<div class="map">
  <!-- 面包屑 -->
  <el-breadcrumb class="bread" separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>
  <!-- 列 -->
  <el-row :gutter="20">
    <el-col :span="8">
      <el-input placeholder="请输入内容" v-model="searchText">
        <el-button
          slot="append"
          @click="startSearch"
          icon="el-icon-search"
        ></el-button>
      </el-input>
    </el-col>
    <el-col :span="8">
      <el-button @click="showAddUserDialog">添加用户</el-button>
    </el-col>
  </el-row>
  <!--
    el-table : 表格
      :data 数据绝对是一个数组

    el-table-column : 列
       prop : 列的数据
   -->
  <el-table :data="userList" style="width: 100%">
    <el-table-column prop="username" label="姓名" width="180">
    </el-table-column>
    <!-- prop 找对象里的值 -->
    <el-table-column prop="email" label="邮箱" width="180"> </el-table-column>
    <el-table-column prop="mobile" label="电话"> </el-table-column>
    <el-table-column prop="type" label="用户状态">
      <template slot-scope="aaa">
        <!-- v-model 直接写的 mg-state 会认为是 data 里的直接属性呢? -->
        <!-- scope 能拿到当前行的对象数据 -->
        <!-- scope.row 能拿到当前行的数据 -->
        <el-switch @change="changeState(aaa.row)" v-model="aaa.row.mg_state">
        </el-switch>
      </template>
    </el-table-column>
    <el-table-column prop="type" label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          plain
          type="primary"
          icon="el-icon-edit"
        ></el-button>
        <el-button
          size="mini"
          @click="delUser(scope.row.id)"
          plain
          type="danger"
          icon="el-icon-delete"
        ></el-button>
        <el-button size="mini" plain type="success"
          ><i class="el-icon-check"></i> 分配角色</el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    @current-change="currentChange"
    background
    layout="prev, pager, next"
    :total="total"
    :page-size="2"
    :current-page="pagenum"
  >
  </el-pagination>

  <!-- 用户添加的对话框 -->
  <!--
    title : 标题
    .sync 是 element-ui 分招的子组件里修改外部组件的方法

   -->

  <el-dialog
    title="收货地址"
    :visible.sync="dialogAddUserVisible"
    @close="closeDialog"
  >
    <el-form
      ref="userForm"
      :rules="rules"
      :model="userForm"
      label-width="100px"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="userForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="userForm.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="userForm.email"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="mobile">
        <el-input v-model="userForm.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogAddUserVisible = false">取 消</el-button>
      <el-button type="primary" @click="addUser">确 定</el-button>
    </div>
  </el-dialog>
</div>
